/*拖拽JS，在需要整体拖拽的DIV的子DIV上添加名为drag的class属性*/
//获取元素
let dragDiv = document.getElementsByClassName('drag')[0];
let dragParentDiv = dragDiv.parentNode,x = 0,y = 0,l = 0,t = 0,isDown = false;
//鼠标按下事件
dragDiv.onmousedown = function(e) {
    //获取x坐标和y坐标
    x = e.clientX;
    y = e.clientY;

    //获取左部和顶部的偏移量
    l = dragParentDiv.offsetLeft;
    t = dragParentDiv.offsetTop;
    //开关打开
    isDown = true;
    //设置样式
    dragDiv.style.cursor = 'move';
}
//鼠标移动
window.onmousemove = function(e) {
    if (!isDown) {
        return;
    }
    //获取x和y
    let nx = e.clientX, ny = e.clientY;
    //计算移动后的左偏移量和顶部的偏移量
    let nl = nx - (x - l), nt = ny - (y - t);
    dragParentDiv.style.left = nl + 'px';
    dragParentDiv.style.top = nt + 'px';
}
//鼠标抬起事件
dragDiv.onmouseup = function() {
    //开关关闭
    isDown = false;
    dragDiv.style.cursor = 'default';
}